package com.zrgk.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DateUtil {
	static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
	static SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
	static SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy/MM/dd");
	static SimpleDateFormat sdf3 = new SimpleDateFormat("yyyy/MM/dd hh:mm:ss");
	/**
	 * yyyy-MM-dd格式字符串转化为Date
	 * @param str
	 * @return
	 */
	public static Date strToDate(String str)
	{
		try {
			return sdf.parse(str);
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			System.out.println("日期转化失败");
		}
		return null;
	}
	/**
	 * yyyy-MM-dd hh:mm:ss格式字符串
	 * @param str
	 * @return
	 */
	public static Date strToDate1(String str)
	{
		try {
			return sdf1.parse(str);
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			System.out.println("日期转化失败");
		}
		return null;
	}
	
	/**
	 * yyyy/MM/dd
	 * @param str
	 * @return
	 */
	public static Date strToDate2(String str)
	{
		try {
			return sdf2.parse(str);
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			System.out.println("日期转化失败");
		}
		return null;
	}
	/**
	 * yyyy/MM/dd hh:mm:ss
	 * @param str
	 * @return
	 */
	public static Date strToDate3(String str)
	{
		try {
			return sdf3.parse(str);
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			System.out.println("日期转化失败");
		}
		return null;
	}
	/**
	 * 把Date类型转换成yyyy-MM-dd字符串
	 * @param date
	 * @return
	 */
	public static String dateToStr(Date date)
	{
		return sdf.format(date);
	}
	/**
	 * 把Date类型转换成yyyy-MM-dd hh:mm:ss字符串
	 * @param date
	 * @return
	 */
	public static String dateToStr1(Date date)
	{
		return sdf1.format(date);
	}
	/**
	 * 把Date类型转换成yyyy/MM/dd字符串
	 * @return
	 */
	public static String dateToStr2(Date date)
	{
		return sdf2.format(date);
	}
	/**
	 * 把Date类型转换成yyyy/MM/dd hh:mm:ss字符串
	 * @param date
	 * @return
	 */
	public static String dateToStr3(Date date)
	{
		return sdf3.format(date);
	}
}
